<template>
  <div class="clientReturnQuery">
    <!-- 客户退货查询 -->
    <div style="border-bottom: 2px solid #f4f4f4; padding-top: 1vh">
      <div class="crq_top">
        <p>客户</p>
        <!-- <el-input class="crq_inp" v-model="customerNo" @blur="customerNoBlur" :disabled="jxAgent"></el-input> -->
        <el-select
          filterable
          style="width: 8vw"
          v-model="customerName"
          @change="
            (e) => {
              this.customerNo = e
            }
          "
          :disabled="jxAgent"
        >
          <el-option
            v-for="item in customerList"
            :key="item.value"
            :label="item.value + '  ' + item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <p>日期</p>
        <el-date-picker
          unlink-panels
          v-model="dateList"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
        <p>客退序号</p>
        <el-input
          class="crq_inp1"
          v-model="inputSequence1"
          clearable
        ></el-input>
        <p>单号</p>
        <el-input
          class="crq_inp1"
          v-model="receiptsNumber"
          clearable
        ></el-input>
        <p>仓库</p>
        <el-input
          class="crq_inp"
          v-model="warehouseNo"
          @blur="warehouseNoBlur"
        ></el-input>
        <el-select
          class="crq_select"
          v-model="warehouseName"
          @change="
            (e) => {
              this.warehouseNo = e
            }
          "
        >
          <el-option
            v-for="item in warehouseList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
            <span style="float: left">{{ item.value }}</span>
            <span style="float: right">{{ item.label }}</span>
          </el-option>
        </el-select>
        <p>季度</p>
        <el-select class="crq_inp1" v-model="quarter" clearable>
          <el-option
            v-for="item in quarterList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </div>
      <div class="crq_top">
        <p>货号</p>
        <el-input class="crq_inp1" v-model="kindsNumber"></el-input>
        <p>品牌</p>
        <el-select class="crq_inp1" v-model="brandedName" clearable>
          <el-option
            v-for="item in brandList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <p>品名</p>
        <el-select class="crq_inp1" v-model="commodityName" clearable>
          <el-option
            v-for="item in commodityNameList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <p>单据状态</p>
        <el-select class="crq_inp1" v-model="affirm">
          <el-option
            v-for="item in affirmList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <p>配货方式</p>
        <el-select class="crq_inp1" v-model="cooperateWay">
          <el-option
            v-for="item in cooperateWayList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <p>总店号</p>
        <el-input
          style="width: 8vw"
          v-model="headOfficeNumber"
          clearable
        ></el-input>
        <p>分店号</p>
        <el-input
          class="crq_inp1"
          v-model="branchNumber"
          clearable
          disabled
        ></el-input>
        <!-- <el-checkbox style="margin:5px 0 0 10px;" v-model="checked">店铺初期</el-checkbox> -->
      </div>
      <div class="crq_top1">
        <div>
          <p>进货客户编号</p>
          <el-input
            style="width: 8vw; margin-right: 12px"
            v-model="inputCustomerNo"
            clearable
          ></el-input>
          <p>厂退厂商编号</p>
          <el-input
            style="width: 8vw; margin-right: 12px"
            v-model="outManufacturerNo"
            clearable
          ></el-input>
          <p>厂退退货序号</p>
          <el-input
            style="width: 8vw"
            v-model="outManufacturerSequence"
          ></el-input>
        </div>
        <div>
          <i
            class="el-icon-question"
            style="color: #017fff; margin: 4px 6px 0 0"
          ></i>
          <p>温馨提示：</p>
          <p>厂退时，请先填好，客户退货序号。</p>
        </div>
      </div>
    </div>

    <div class="crq_button">
      <div>
        <el-button @click="search(1)" icon="el-icon-search" type="primary"
          >查询</el-button
        >
        <el-button
          @click="confirm"
          icon="el-icon-circle-check"
          :disabled="isConfirm"
          >确认</el-button
        >
        <el-button
          @click="pickUp"
          icon="el-icon-circle-check"
          :disabled="!isConfirm || pick"
          >收货</el-button
        >
        <!-- <el-button @click="audit" icon="el-icon-coordinate" :disabled="isAudit">审核</el-button>
        <el-button @click="umpire" icon="el-icon-coordinate" :disabled="!isAudit">反审</el-button> -->
        <!-- <el-button @click="supplement" icon="el-icon-document-add" :disabled="jxChangeOrder">补单</el-button>
        <el-button @click="revision" icon="el-icon-edit-outline" :disabled="jxChangeOrder">改单</el-button> -->
        <el-button
          @click="supplement"
          icon="el-icon-document-add"
          :disabled="Dis1"
          >补单</el-button
        >
        <el-button @click="revision" icon="el-icon-edit-outline"
          >改单</el-button
        >
        <el-button @click="Export" icon="el-icon-upload2">导出</el-button>
        <el-button @click="Print" icon="el-icon-printer">列印</el-button>
        <el-button
          @click="customerInput"
          icon="el-icon-set-up"
          :disabled="!isConfirm || isOut1"
          >客户整进</el-button
        >
        <el-button
          @click="ManufacturerReturn"
          icon="el-icon-set-up"
          :disabled="!isConfirm || isOut2"
          >厂商整退</el-button
        >
        <!-- <el-button @click="dele" icon="el-icon-delete" :disabled="jxChangeOrder">删除</el-button> -->
        <el-button @click="dele" icon="el-icon-delete" :disabled="Dis"
          >删除</el-button
        >
      </div>
      <div style="float: right; white-space: nowrap; display: flex">
        <div style="margin-top: 5px; display: flex">
          <div class="tip" style="background: #6bcc7b"></div>
          :已完成
          <div class="tip" style="background: #ffb700"></div>
          :未收货
          <div class="tip" style="background: #ff0000"></div>
          :
          <p style="margin-right: 15px">未确认</p>
          <!-- <div class="tip" style="background:#017aff;"></div>:<p style="margin-right:15px;">调货摘要</p> -->
        </div>
        <el-checkbox
          style="margin: 0"
          v-model="adjustPrice"
          border
          :disabled="twoDimensional"
          >查询调整过售价</el-checkbox
        >
        <el-checkbox
          style="margin: 0 0 0 10px"
          v-model="twoDimensional"
          border
          :disabled="adjustPrice"
          >二维</el-checkbox
        >
      </div>
    </div>

    <div class="crq_tab">
      <div id="content1">
        <el-table
          ref="table1"
          border
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '30px'
          }"
          :cell-style="changeCellStyle"
          :data="sequenceData"
          height="65.5vh"
          style="width: 100%"
          highlight-current-row
          @row-click="rowClick"
        >
          <el-table-column
            type="index"
            label="序号"
            width="50"
          ></el-table-column>
          <el-table-column label="单据状态" width="80">
            <template slot-scope="scope">
              <div style="display: flex; text-align: center">
                <div
                  class="tip1"
                  :style="{
                    background:
                      scope.row.sequenceStatus == 0
                        ? '#FF0000'
                        : scope.row.sequenceStatus == 1
                        ? '#FFB700'
                        : '#6BCC7B'
                  }"
                ></div>
                <p>
                  {{
                    scope.row.sequenceStatus == 0
                      ? '未确认'
                      : scope.row.sequenceStatus == 1
                      ? '未收货'
                      : '已完成'
                  }}
                </p>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="调货" width="40">
            <template slot-scope="scope">
              <div
                style="
                  display: flex;
                  text-align: center;
                  width: 80px;
                  padding-left: 8px;
                "
              >
                <div
                  :style="{
                    display: scope.row.sequenceStatus == 3 ? 'black' : 'none'
                  }"
                >
                  <i class="el-icon-check"></i>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="outSequence"
            label="客退序号"
            width="120"
          ></el-table-column>
          <el-table-column
            prop="outTime"
            label="退货日期"
            width="100"
          ></el-table-column>
          <el-table-column
            prop="sendTime"
            label="寄货日期"
            width="100"
          ></el-table-column>
          <el-table-column
            prop="customerStr"
            label="客户"
            min-width="120"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="number"
            label="数量"
            width="60"
          ></el-table-column>
          <el-table-column
            prop="money"
            label="金额"
            width="100"
          ></el-table-column>
          <!-- <el-table-column prop="affirm" label="确认" width="50"></el-table-column>
          <el-table-column prop="mnemonicCode" label="收货" width="50"></el-table-column> -->
          <!-- <el-table-column prop="checks" label="审核" width="50"></el-table-column> -->
          <el-table-column
            prop="remark"
            label="备注"
            min-width="200"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="transferCargoInfo"
            label="调货摘要"
            min-width="200"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="operator"
            label="操作员"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="cooperateWay"
            label="配货方式"
            width="80"
          ></el-table-column>
        </el-table>
        <el-pagination
          small
          background
          ref="paginationLeft"
          layout="prev, pager, next, jumper, sizes"
          :page-sizes="[20, 50, 100, 200]"
          :page-size="limitLeft"
          :page-count="pagesNumLeft"
          :total="dataLenLeft"
          @current-change="handleCurrentChangeLeft"
          @size-change="handleSizeChangeLeft"
        ></el-pagination>
      </div>
      <div class="divider" @click="dividerClick">
        <i v-if="!areaFlag" class="el-icon-arrow-right"></i>
        <i v-if="areaFlag" class="el-icon-arrow-left"></i>
      </div>
      <div id="content2">
        <el-table
          id="outTable"
          border
          ref="table2"
          :data="kindsNumberData"
          height="65.5vh"
          show-summary
          :summary-method="getSummaries"
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '30px'
          }"
          :cell-style="{ padding: 0, height: '26px' }"
          style="width: 100%"
          highlight-current-row
          @row-click="detailClick"
        >
          <el-table-column
            type="index"
            label="序号"
            width="50"
          ></el-table-column>
          <template v-for="i in knhList">
            <el-table-column
              :prop="i.prop"
              :label="i.label"
              :width="i.width"
              :key="i.prop"
              v-if="i.isShow"
              show-overflow-tooltip
            ></el-table-column>
          </template>
        </el-table>
        <el-pagination
          small
          background
          ref="paginationRight"
          layout="prev, pager, next, jumper, sizes"
          :page-sizes="[20, 50, 100, 200]"
          :page-size="limit"
          :page-count="pagesNum"
          :total="dataLen"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        ></el-pagination>
      </div>
    </div>
    <!-- 列印 -->
    <div class="print" v-if="showPrint">
      <div>列印方式</div>
      <el-radio v-model="printType" label="1">双打</el-radio>
      <el-radio v-model="printType" label="2">发货单</el-radio>
      <el-radio v-model="printType" label="3">地址</el-radio>
      <div>
        <el-button
          @click="
            () => {
              this.showPrint = false
            }
          "
          >取消</el-button
        >
        <el-button @click="printConfirm" type="primary">确定</el-button>
      </div>
    </div>
    <!-- 导出 -->
    <div class="exPort" v-show="showExport">
      <div>导出方式</div>
      <el-radio v-model="exportType" label="1">导出左表</el-radio>
      <el-radio v-model="exportType" label="2">导出右表</el-radio>
      <!-- <el-radio v-model="exportType" label="2">导出客户进货明细</el-radio> -->
      <div>
        <el-button
          @click="
            () => {
              this.showExport = false
            }
          "
          >取消</el-button
        >
        <el-button @click="exportConfirm" type="primary">确定</el-button>
      </div>
    </div>
    <!-- 改单密码验证 -->
    <verify-password
      v-if="showpwd"
      :operationType="operationType"
      :isConfirm="isConfirm"
      @closepwd="
        () => {
          this.showpwd = false
        }
      "
      @showRevision="showRevision"
    ></verify-password>
    <!-- 改单 -->
    <trevi-sion
      :Str="this.Str"
      v-show="showCReviSion"
      :flag="showCReviSion"
      :customerL="customerList"
      :warehouseL="warehouseList"
      :selectInputSequence="inputSequence"
      :detailRow="detailRow"
      @closeReviSion="
        () => {
          this.showCReviSion = false
        }
      "
      @modifySuc="search"
    ></trevi-sion>
    <!-- 补单输入框 -->
    <sup-order
      v-show="showSupOrder"
      :sequence="inputSequence"
      @closeuopplement="
        () => {
          this.showSupOrder = false
        }
      "
      @determine="determine"
    ></sup-order>
    <!-- 底部框 -->
    <foot-view class="footView">
      <div slot="text">
        <el-popover
          placement="top-start"
          width="120"
          max-height="100px"
          trigger="click"
        >
          <el-checkbox-group v-model="selectHeaderList">
            <el-checkbox
              v-for="i in headerList"
              :label="i.value"
              :key="i.value"
              style="margin-bottom: 7px"
            ></el-checkbox>
          </el-checkbox-group>
          <i slot="reference" class="el-icon-date">表头配置</i></el-popover
        >
        <span>数据库：{{ jxQuarter }}</span>
        <span>操作员：{{ operator }}</span>
        <span>记录数：{{ amount }}</span>
      </div>
    </foot-view>

    <!-- <print-area 
      v-show=false 
      isInput='退' 
      isVendor="客户" 
      :manufacturerName="printVendorName" 
      :principal="principal" 
      :phone="phone" :address="address" 
      :remark="printRemark" 
      :inputSequence="inputSequence" 
      :jxQuarter="jxQuarter" 
      :inputDate="inputDate" 
      :printTotal="printTotal" 
      :printMoney="printMoney" 
      :printStyle="printStyle" 
      :printSellingPrice="printSellingPrice" 
      :printType="printType" 
      :shipType="shipType" 
      :cellphone="cellphone" 
      :companyName="companyName" 
      :companyPhone="companyPhone"></print-area> -->

    <div id="p" v-show="false"></div>
  </div>
</template>

<script>
const resources = require('../../../config/printCSS')

import footView from '../../../components/FootView'
import verifyPassword from '../../../components/VerifyPassword'
import supOrder from '../../../components/SupOrder'
import treviSion from './childComps/TReviSion'
import printArea from '../../../components/PrintVendorStock'

import { getClient } from '../../../network/client'
import { getWarehouse } from '../../../network/warehouse'
import { getProductName } from '../../../network/productName'
import { getBranded } from '../../../network/branded'
import {
  getOutInquire,
  getAdjustmentSellingPrice,
  affirmOut,
  receipt,
  checkYse,
  checkNo,
  allOut,
  retreat
} from '../../../network/customerOutTotal'
import { getSystemConfig } from '../../../network/operatoryCommand'
import { getQuarter } from '../../../network/quarter'

import today from '../../../components/mixins/today'
import enterUp from '../../../components/mixins/enterUp'
import cookieFn from '../../../components/mixins/cookieFn'

import table2excel from 'js-table2excel'
import QRCode from 'qrcode'

import { newCloumn } from '../../../util/exportExcelTitle'

export default {
  name: 'client_return_query',
  mixins: [today, enterUp, cookieFn],
  components: {
    footView,
    verifyPassword,
    supOrder,
    treviSion,
    printArea
  },
  data() {
    return {
      Str: '',
      strRandom: Math.random().toString(36).substring(2, 7), //随机字符串
      Dis: false,
      Dis1: false,
      inpList: [],
      // 总数据条数
      dataLenLeft: 0,
      // 总页码
      pagesNumLeft: 0,
      // 分页条数
      limitLeft: 20,
      // 当前页码
      currentPageLeft: 1,

      // 总数据条数
      dataLen: 0,
      // 总页码
      pagesNum: 0,
      // 分页条数
      limit: 20,
      // 当前页码
      currentPage: 1,

      props: { multiple: true },

      // 按钮
      isConfirm: false,
      isAudit: false,
      isOut1: false,
      isOut1: false,
      isOut2: false,
      isRFID: false,
      pick: false,

      customerNo: '',
      customerName: '',
      customerList: [],
      dateList: null,
      inputSequence: '',
      // 查询条件的序号
      inputSequence1: '',
      receiptsNumber: '',
      warehouseNo: '',
      warehouseName: '',
      warehouseList: [],
      quarter: '',
      quarterList: [],
      kindsNumber: '',
      kindsNumberL: [],
      brandedName: '',
      brandList: [],
      commodityName: '',
      commodityNameList: [],
      affirm: '全部',
      affirmList: [
        { value: '全部', label: '全部' },
        { value: '未确认', label: '未确认' },
        { value: '未收货', label: '未收货' },
        { value: '已完成', label: '已完成' }
      ],
      cooperateWay: '全部',
      cooperateWayList: [
        { value: '全部', label: '全部' },
        { value: '配货', label: '配货' },
        { value: '订货', label: '订货' },
        { value: '订断', label: '订断' },
        { value: '追断', label: '追断' }
      ],
      headOfficeNumber: '',
      branchNumber: '',
      remark: '',
      inputCustomerNo: '',
      outManufacturerNo: '',
      outManufacturerSequence: '',
      amount: 0,

      // 左表
      sequenceData: [],
      sequenceDataList: [],

      // 右表
      kindsNumberData: [],
      // 右总表
      kindsNumberList: [],
      // 按条件查询出来的右总表
      conditionList: [],
      // 右二维表
      styleNumberList: [],
      // 查询调整过售价表
      adjustPriceList: [],
      // 选中的表
      selectList: [],
      // 每单二维表
      detailTwo: [],

      beginningPeriod: false,
      adjustPrice: false,
      twoDimensional: false,

      showPrint: false,
      showExport: false,
      showpwd: false,
      showCReviSion: false,
      showSupOrder: false,

      operationType: 0,

      printType: '1',
      exportType: '1',

      knhList: [],
      // 默认表头
      knhList1: [
        { prop: 'sequence', label: '客退序号', width: '120', isShow: true },
        { prop: 'no', label: '客户编号', width: '80', isShow: true },
        { prop: 'name', label: '客户简称', width: '100', isShow: true },
        { prop: 'kindsNumber', label: '货号', width: '160', isShow: true },
        { prop: 'styleNumber', label: '款号', width: '100', isShow: true },
        { prop: 'colorNo', label: '颜色编号', width: '80', isShow: true },
        { prop: 'colorName', label: '颜色名称', width: '80', isShow: true },
        { prop: 'size', label: '尺码', width: '50', isShow: true },
        { prop: 'commodityName', label: '品名', width: '160', isShow: true },
        { prop: 'sellingPrice', label: '售价', width: '70', isShow: true },
        { prop: 'discount', label: '折数', width: '50', isShow: true },
        { prop: 'onePrice', label: '单价', width: '70', isShow: true },
        { prop: 'sum', label: '数量', width: '60', isShow: true },
        { prop: 'money', label: '金额', width: '90', isShow: true },
        { prop: 'time', label: '客退日期', width: '100', isShow: true },
        { prop: 'remark', label: '备注', width: '160', isShow: true },
        { prop: 'entryTime', label: '录入时间', width: '160', isShow: true }
      ],
      // 二维表头
      knhList2: [
        { prop: 'typeNumber', label: '款号', width: '120', isShow: true },
        { prop: 'colorName', label: '颜色', width: '100', isShow: true },
        { prop: 'c05', label: '05-XS', width: '100', isShow: true },
        { prop: 'c07', label: '07-S', width: '100', isShow: true },
        { prop: 'c09', label: '09-M', width: '100', isShow: true },
        { prop: 'c11', label: '11-L', width: '100', isShow: true },
        { prop: 'c13', label: '13-XL', width: '100', isShow: true },
        { prop: 'c15', label: '15-2L', width: '100', isShow: true },
        { prop: 'c17', label: '17-3L', width: '100', isShow: true },
        { prop: 'c19', label: '19-4L', width: '100', isShow: true },
        { prop: 'c21', label: '21-5L', width: '100', isShow: true },
        { prop: 'c23', label: '23-6L', width: '100', isShow: true },
        { prop: 'f', label: 'F', width: '100', isShow: true },
        { prop: 'total', label: '小计', width: '80', isShow: true },
        { prop: 'sellingPrice', label: '售价', width: '100', isShow: true },
        { prop: 'onePrice', label: '单价', width: '100', isShow: true },
        { prop: 'money', label: '金额', width: '100', isShow: true },
        { prop: 'commodityName', label: '品名', width: '100', isShow: true },
        { prop: 'brandedName', label: '品牌', width: '100', isShow: true },
        { prop: 'quarter', label: '季度', width: '80', isShow: true }
      ],
      // 查询调整过售价
      knhList4: [
        { prop: 'sequence', label: '客退序号', width: '', isShow: true },
        { prop: 'no', label: '客户编号', width: '100', isShow: true },
        { prop: 'kindsNumber', label: '货号', width: '', isShow: true },
        { prop: 'sellingPrice', label: '售价', width: '120', isShow: true },
        {
          prop: 'fileSellingPrice',
          label: '建档售价',
          width: '120',
          isShow: true
        },
        { prop: 'sum', label: '数量', width: '100', isShow: true }
      ],

      detailRow: {},
      sequenceRow: {},

      operator: this.getCookie('jxUser'),
      jxQuarter: this.getCookie('jxQuarter'),
      jxAgent: this.getCookie('jxAgent') == '1',
      jxChangeOrder: this.getCookie('jxChangeOrder') == '0',

      // 设置表头
      selectHeaderList: [
        '客退序号',
        '客户',
        '客户编号',
        '客户简称',
        '货号',
        '款号',
        '颜色编号',
        '颜色名称',
        '尺码',
        '品名',
        '售价',
        '折数',
        '单价',
        '数量',
        '金额',
        '附件',
        '客退日期',
        '备注',
        '仓库编号',
        '录入时间'
      ],
      headerList: [
        { value: '客退序号' },
        { value: '客户' },
        { value: '客户编号' },
        { value: '客户简称' },
        { value: '货号' },
        { value: '款号' },
        { value: '颜色编号' },
        { value: '颜色名称' },
        { value: '尺码' },
        { value: '品名' },
        { value: '售价' },
        { value: '折数' },
        { value: '单价' },
        { value: '数量' },
        { value: '金额' },
        { value: '附件' },
        { value: '客退日期' },
        { value: '备注' },
        { value: '仓库编号' },
        { value: '录入时间' }
      ],

      // 打印
      styleList: [],
      printTotal: 0,
      printMoney: 0,
      // 款号合计
      printStyle: 0,
      // 售价合计
      printSellingPrice: 0,
      // 客户
      printVendor: '',
      printVendorName: '',
      principal: '',
      contact: '',
      phone: '',
      cellphone: '',
      inputDate: '',
      address: '',
      shipType: '',
      printRemark: '',
      companyName: '',
      companyPhone: '',

      summation: {},

      areaFlag: false,

      canvasUrl: ''
    }
  },
  watch: {
    twoDimensional(a, b) {
      this.currentPage = 1
      this.currentPageLeft = 1
      this.$refs.paginationRight.internalCurrentPage = 1
      if (this.adjustPrice) this.adjustPrice = false
      this.search(1)
      if (a) {
        // 显示二维表
        this.dataLen = this.styleNumberList.length
        this.knhList = this.knhList2
        this.kindsNumberData = this.styleNumberList.slice(0, this.limit)

        if (localStorage.getItem('jx_Ttitle2')) {
          this.selectHeaderList = localStorage.getItem('jx_Ttitle2').split(',')
        } else {
          this.selectHeaderList = [
            '款号',
            '颜色',
            '05-XS',
            '07-S',
            '09-M',
            '11-L',
            '13-XL',
            '15-2L',
            '17-3L',
            '19-4L',
            '21-5L',
            '23-6L',
            'F',
            '小计',
            '品名',
            '售价',
            '单价',
            '金额',
            '品牌',
            '季度'
          ]
        }

        this.headerList = [
          { value: '款号' },
          { value: '颜色' },
          { value: '05-XS' },
          { value: '07-S' },
          { value: '09-M' },
          { value: '11-L' },
          { value: '13-XL' },
          { value: '15-2L' },
          { value: '17-3L' },
          { value: '19-4L' },
          { value: '21-5L' },
          { value: '23-6L' },
          { value: 'F' },
          { value: '小计' },
          { value: '品名' },
          { value: '售价' },
          { value: '单价' },
          { value: '金额' },
          { value: '品牌' },
          { value: '季度' }
        ]
      } else {
        this.knhList = this.knhList1

        if (localStorage.getItem('jx_Ttitle1')) {
          this.selectHeaderList = localStorage.getItem('jx_Ttitle1').split(',')
        } else {
          this.selectHeaderList = [
            '客退序号',
            '客户',
            '客户编号',
            '客户简称',
            '货号',
            '款号',
            '颜色编号',
            '颜色名称',
            '尺码',
            '品名',
            '售价',
            '折数',
            '单价',
            '数量',
            '金额',
            '附件',
            '客退日期',
            '备注',
            '仓库编号',
            '录入时间'
          ]
        }

        this.headerList = [
          { value: '客退序号' },
          { value: '客户' },
          { value: '客户编号' },
          { value: '客户简称' },
          { value: '货号' },
          { value: '款号' },
          { value: '颜色编号' },
          { value: '颜色名称' },
          { value: '尺码' },
          { value: '品名' },
          { value: '售价' },
          { value: '折数' },
          { value: '单价' },
          { value: '数量' },
          { value: '金额' },
          { value: '附件' },
          { value: '客退日期' },
          { value: '备注' },
          { value: '仓库编号' },
          { value: '录入时间' }
        ]
        if (this.inputSequence) {
          this.dataLen = this.selectList.length
          this.kindsNumberData = this.selectList.slice(0, this.limit)
        } else {
          this.dataLen = this.kindsNumberList.length
          this.kindsNumberData = this.conditionList.slice(0, this.limit)
        }
      }
    },
    adjustPrice(a, b) {
      this.currentPage = 1
      this.currentPageLeft = 1
      this.$refs.paginationRight.internalCurrentPage = 1
      this.$refs.paginationLeft.internalCurrentPage = 1
      this.dataLen = 0
      this.dataLenLeft = 0
      this.sequenceData = []
      this.kindsNumberData = []
      this.kindsNumberList = []
      this.styleNumberList = []
      if (a) {
        getAdjustmentSellingPrice().then((res) => {
          this.knhList = this.knhList4
          this.adjustPriceList = res.data.data
          this.dataLen = this.adjustPriceList.length

          this.summation.sum = 0
          this.summation.sellingPriceMoney = 0
          this.summation.money = 0
          this.adjustPriceList.forEach((e) => {
            this.summation.sum += Number(e.sum)
            this.summation.sellingPriceMoney += Number(e.sellingPriceMoney)
            this.summation.money += Number(e.money)
          })
          this.kindsNumberData = this.adjustPriceList.slice(0, this.limit)
        })
      } else {
        this.knhList = this.knhList1
        this.search()
      }
    },
    selectHeaderList(a, b) {
      let tmpList = []
      let tmpList2 = []
      let tmpList4 = []
      this.headerList.forEach((e) => {
        if (a.indexOf(e.value) == -1) {
          tmpList = this.knhList1.filter((i) => {
            return i.label == e.value
          })
          if (tmpList.length) tmpList[0].isShow = false
          tmpList2 = this.knhList2.filter((i) => {
            return i.label == e.value
          })
          if (tmpList2.length) tmpList2[0].isShow = false
          tmpList4 = this.knhList4.filter((i) => {
            return i.label == e.value
          })
          if (tmpList4.length) tmpList4[0].isShow = false
        } else {
          tmpList = this.knhList1.filter((i) => {
            return i.label == e.value
          })
          if (tmpList.length) tmpList[0].isShow = true
          tmpList2 = this.knhList2.filter((i) => {
            return i.label == e.value
          })
          if (tmpList2.length) tmpList2[0].isShow = true
          tmpList4 = this.knhList4.filter((i) => {
            return i.label == e.value
          })
          if (tmpList4.length) tmpList4[0].isShow = true
        }
      })
      if (this.twoDimensional) {
        localStorage.setItem('jx_Ttitle2', this.selectHeaderList.toString())
      } else {
        localStorage.setItem('jx_Ttitle1', this.selectHeaderList.toString())
      }
    },
    dataLen(a, b) {
      this.pagesNum = Math.ceil(this.dataLen / this.limit)
    },
    limit(a, b) {
      this.pagesNum = Math.ceil(this.dataLen / this.limit)
    },
    dataLenLeft(a, b) {
      this.pagesNumLeft = Math.ceil(this.dataLenLeft / this.limitLeft)
    },
    limitLeft(a, b) {
      this.pagesNumLeft = Math.ceil(this.dataLenLeft / this.limitLeft)
    },
    $route(a, b) {
      if (b.path.indexOf('delete_document') != -1) this.search()
    },
    customerNo(a, b) {
      this.customerNo = a.toUpperCase().trim()
      this.currentPageLeft = 1
    },
    inputSequence1(a, b) {
      this.inputSequence1 = a.toUpperCase().trim()
      this.currentPageLeft = 1
    },
    receiptsNumber(a, b) {
      this.receiptsNumber = a.toUpperCase().trim()
    },
    warehouseNo(a, b) {
      this.warehouseNo = a.toUpperCase().trim()
      this.currentPageLeft = 1
    },
    kindsNumber(a, b) {
      this.kindsNumber = a.toUpperCase().trim()
      this.currentPageLeft = 1
    },
    headOfficeNumber(a, b) {
      this.headOfficeNumber = a.toUpperCase().trim()
      this.currentPageLeft = 1
    },
    inputCustomerNo(a, b) {
      this.inputCustomerNo = a.toUpperCase().trim()
    },
    outManufacturerNo(a, b) {
      this.outManufacturerNo = a.toUpperCase().trim()
    },
    outManufacturerSequence(a, b) {
      this.outManufacturerSequence = a.toUpperCase().trim()
    },
    dateList(a, b) {
      this.currentPageLeft = 1
    },
    printVendor(a, b) {
      if (!a) return
      getClient({ no: a }).then((res) => {
        this.principal = res.data.data[0].principal || res.data.data[0].name
        this.contact = res.data.data[0].contact || res.data.data[0].name
        this.cellphone = res.data.data[0].phone || ''
        this.phone = res.data.data[0].cellphone || ''
        this.address = res.data.data[0].address || ''
      })
    }
  },
  methods: {
    // 补单
    supplement() {
      if (this.showpwd || this.showExport || this.showPrint) return
      if (!this.pick) {
        this.$message.info('店铺数据仅支持收货操作')
        return
      }
      if (!this.inputSequence) {
        this.$alert('请先选择一条数据再进行补单操作', '', {
          confirmButtonText: '确定'
        })
        return
      }
      let min =
        new Date().getMinutes() < 10
          ? '0' + new Date().getMinutes()
          : new Date().getMinutes()
      let sec =
        new Date().getSeconds() < 10
          ? '0' + new Date().getSeconds()
          : new Date().getSeconds()
      console.log(this.strRandom + min + sec) //随机字符串加时间      不重复随机字符串
      this.Str = this.strRandom + min + sec
      this.operationType = 1
      this.showpwd = true
    },
    // 改单
    revision() {
      if (this.showSupOrder || this.showExport || this.showPrint) return
      if (!this.pick) {
        this.$message.info('店铺数据仅支持收货操作')
        return
      }
      if (!this.inputSequence) {
        this.$alert('请先选择一条数据再进行改单操作', '', {
          confirmButtonText: '确定'
        })
        return
      }
      let min =
        new Date().getMinutes() < 10
          ? '0' + new Date().getMinutes()
          : new Date().getMinutes()
      let sec =
        new Date().getSeconds() < 10
          ? '0' + new Date().getSeconds()
          : new Date().getSeconds()
      console.log(this.strRandom + min + sec) //随机字符串加时间      不重复随机字符串
      this.Str = this.strRandom + min + sec
      this.operationType = 2
      this.showpwd = true
    },
    // 导出
    Export() {
      if (this.showpwd || this.showSupOrder || this.showPrint) return
      this.showExport = true
    },
    // 确认导出
    exportConfirm() {
      this.showExport = false
      let column
      let tmpData = []
      switch (this.exportType) {
        case '1':
          // 导出汇总表
          column = [
            { key: 'outSequence', title: '客退序号', type: 'text' },
            { key: 'outTime', title: '送货日期', type: 'text' },
            { key: 'customerStr', title: '客户', type: 'text' },
            { key: 'number', title: '数量', type: 'text' },
            { key: 'money', title: '金额', type: 'text' },
            { key: 'affirm', title: '确认', type: 'text' },
            { key: 'remark', title: '备注', type: 'text' },
            { key: 'operator', title: '操作员', type: 'text' },
            { key: 'cooperateWay', title: '配货方式', type: 'text' }
          ]
          table2excel(column, this.sequenceDataList, '客户退货汇总表.xls')
          break
        case '2':
          // 导出明细表
          if (this.adjustPrice) {
            column = [
              { key: 'sequence', title: '客退序号', type: 'text' },
              { key: 'no', title: '客户编号', type: 'text' },
              { key: 'kindsNumber', title: '货号', type: 'text' },
              { key: 'sellingPrice', title: '售价', type: 'text' },
              { key: 'fileSellingPrice', title: '建档售价', type: 'text' },
              { key: 'sum', title: '数量', type: 'text' }
            ]
            table2excel(column, this.adjustPriceList, '客户退货调整过售价.xls')
            return
          }
          if (this.twoDimensional) {
            column = [
              { key: 'typeNumber', title: '款号', type: 'text' },
              { key: 'colorName', title: '颜色', type: 'text' },
              { key: 'c05', title: '05-XS', type: 'text' },
              { key: 'c07', title: '07-S', type: 'text' },
              { key: 'c09', title: '09-M', type: 'text' },
              { key: 'c11', title: '11-L', type: 'text' },
              { key: 'c13', title: '13-XL', type: 'text' },
              { key: 'c15', title: '15-2L', type: 'text' },
              { key: 'c17', title: '17-3L', type: 'text' },
              { key: 'c19', title: '19-4L', type: 'text' },
              { key: 'c21', title: '21-5L', type: 'text' },
              { key: 'c23', title: '23-6L', type: 'text' },
              { key: 'f', title: 'F', type: 'text' },
              { key: 'total', title: '小计', type: 'text' },
              { key: 'sellingPrice', title: '售价', type: 'text' },
              { key: 'onePrice', title: '单价', type: 'text' },
              { key: 'sellingPriceMoney', title: '金额', type: 'text' },
              { key: 'commodityName', title: '品名', type: 'text' },
              { key: 'brandedName', title: '品牌', type: 'text' },
              { key: 'quarter', title: '季度', type: 'text' }
            ]
            column = newCloumn(column, this.selectHeaderList)
            table2excel(column, this.styleNumberList, '客户退货明细表2.xls')
          } else {
            column = [
              { key: 'sequence', title: '客退序号', type: 'text' },
              { key: 'no', title: '客户编号', type: 'text' },
              { key: 'name', title: '客户简称', type: 'text' },
              { key: 'kindsNumber', title: '货号', type: 'text' },
              { key: 'styleNumber', title: '款号', type: 'text' },
              { key: 'colorNo', title: '颜色编号', type: 'text' },
              { key: 'colorName', title: '颜色名称', type: 'text' },
              { key: 'size', title: '尺码', type: 'text' },
              { key: 'commodityName', title: '品名', type: 'text' },
              { key: 'sellingPrice', title: '售价', type: 'text' },
              { key: 'discount', title: '折数', type: 'text' },
              { key: 'onePrice', title: '单价', type: 'text' },
              { key: 'sum', title: '数量', type: 'text' },
              { key: 'money', title: '金额', type: 'text' },
              { key: 'time', title: '客退日期', type: 'text' },
              { key: 'remark', title: '备注', type: 'text' },
              { key: 'entryTime', title: '录入时间', type: 'text' }
            ]
            column = newCloumn(column, this.selectHeaderList)
            if (this.inputSequence) {
              table2excel(column, this.selectList, '客户退货明细表1.xls')
            } else {
              table2excel(column, this.kindsNumberList, '客户退货明细表1.xls')
            }
          }
      }
    },
    // 列印
    Print() {
      if (!this.styleNumberList.length) {
        this.$message.info('请勾选二维表')
        return
      }
      if (this.showpwd || this.showExport || this.showSupOrder) return
      this.showPrint = true
      this.styleList = []
      this.printTotal = 0
      this.printMoney = 0
      this.printStyle = 0
      this.printSellingPrice = 0
    },
    printConfirm() {
      // console.log('点击确定了')
      this.showPrint = false
      let printArea = document.getElementById('p')
      if (this.printType != '3') {
        printArea.innerHTML = `
          <div style="margin-top: 20px;">
            <p class="rightTag" style="top: 3cm;">白联仓库 红联财务 黄联客户</p>
            <span class="printHead">
              ${this.companyName}${this.jxQuarter}客户退货单
            </span>
            <div class="qrInfo" style="height: 25px;">
              <p style="margin: 5px 0;">客户：${this.printVendorName}</p>
              <p style="margin: 5px 0;">联系人：${this.contact}</p>
              <p style="margin: 5px 0;">退货序号：${this.inputSequence}</p>
            </div>
            <div class="qrInfo" style="height: 25px;">
              <p style="margin: 5px 0;">客户电话：${this.phone}</p>
              <p style="margin: 5px 0;">出货类型：${this.shipType}</p>
              <p style="margin: 5px 0;">退货日期：${this.inputDate}</p>
            </div>
            <canvas id="canvas"></canvas>
          </div>
          
          <table 
            border="1" 
            align="center" 
            id="printTable">
            <thead>
              <tr>
                <td style="width: 4%;padding: 0;" rowspan="2">序号</td>
                <td style="width: 15%;padding: 0;" rowspan="2">型色</td>
                <td style="width: 8%;padding: 0;" rowspan="2">颜色</td>
                <td style="width: 15%;padding: 0;" rowspan="2">品名</td>
                <td style="width: 3.8%;padding: 0;" nowrap="nowrap">05</td>
                <td style="width: 3.8%;padding: 0;" nowrap="nowrap">07</td>
                <td style="width: 3.8%;padding: 0;" nowrap="nowrap">09</td>
                <td style="width: 3.8%;padding: 0;" nowrap="nowrap">11</td>
                <td style="width: 3.8%;padding: 0;" nowrap="nowrap">13</td>
                <td style="width: 3.8%;padding: 0;" nowrap="nowrap">15</td>
                <td style="width: 3.8%;padding: 0;" nowrap="nowrap">17</td>
                <td style="width: 3.8%;padding: 0;" nowrap="nowrap">19</td>
                <td style="width: 3.8%;padding: 0;" nowrap="nowrap">21</td>
                <td style="width: 3.8%;padding: 0;" nowrap="nowrap">23</td>
                <td style="width: 3.8%;padding: 0;">F</td>
                <td rowspan="2" style="width: 5%;">数量</td>
                <td rowspan="2" style="width: 5%;">单价</td>
                <td rowspan="2">金额</td>
              </tr>
              <tr>
                <td style="border-top: 1px dotted;border-left: 1px dotted;">XS</td>
                <td style="border-top: 1px dotted;">S</td>
                <td style="border-top: 1px dotted;">M</td>
                <td style="border-top: 1px dotted;">L</td>
                <td style="border-top: 1px dotted;">XL</td>
                <td style="border-top: 1px dotted;">2L</td>
                <td style="border-top: 1px dotted;">3L</td>
                <td style="border-top: 1px dotted;">4L</td>
                <td style="border-top: 1px dotted;">5L</td>
                <td style="border-top: 1px dotted;">6L</td>
                <td style="border-top: 1px dotted;"></td>
              </tr>
            </thead>
          </table>
        `
        this.$confirm('是否使用A4纸打印', '提示', {
          distinguishCancelAndClose: true,
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning'
        })
          .then(() => {
            // 用A4纸
            // console.log('用A4纸')
            this.openPrint(true)
          })
          .catch((action) => {
            // 用半张A4纸
            if (action == 'cancel') {
              // console.log('用半张A4纸')
              this.openPrint(false)
            }
          })
      } else {
        printArea.innerHTML = `
          <div id="printA">
            <div class="addressH1">
              <p>收货地址：${this.address}</p>
            </div>
            <div class="addressH1">
              <p>收货人：${this.printVendorName.split('_')[1]}</p>
            </div>
            <div class="addressH1">
              <p>电话：${this.cellphone}</p>
            </div>
            <div class="addressH1">
              <p>手机：${this.phone}</p>
            </div>
            <div class="addressH2">
              <p>寄件人：${this.companyName}</p>
              <p>联系电话：${this.companyPhone}</p>
            </div>
            <div class="addressH2">
              <p>备注：${this.printRemark || ''}</p>
            </div>
            <div class="addressH2">
              <p>单据类型：${this.shipType}</p>
              <p>单据序号：${this.inputSequence}</p>
              <p>${this.printStyle}</p>
            </div>
            <div class="addressH2">
              <p>制单人：${this.operator}</p>
              <p>${this.inputDate}</p>
            </div>
          </div>
        `
        this.styleNumberList.forEach((e) => {
          this.printStyleCount(e.typeNumber)
        })
        this.printStyle = this.styleList.length
        let int = setInterval(() => {
          if (this.printStyle) {
            clearInterval(int)
            let printHtml = document.getElementById('p').innerHTML
            let wind = window.open(
              '',
              'newwindow',
              'height=500, width=1000, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'
            )
            wind.document.body.innerHTML = printHtml
            let style = document.createElement('style')
            style.type = 'text/css'
            style.innerHTML = resources.printCSS
            wind.document.head.appendChild(style)
            wind.print()
          }
        }, 100)
      }
    },
    openPrint(isA4, x = 1, id = 'printTable') {
      let index = --x
      let printTable = document.getElementById(id)
      let length = this.styleNumberList.length

      for (index; index < length; index++) {
        const e = this.styleNumberList[index]
        // console.log(index)
        // console.log(index+1)
        this.printTotal += Number(e.total)
        this.printMoney += Number(e.money)
        this.printSellingPrice += Number(e.sellingPriceMoney)

        let row = printTable.insertRow(printTable.FetchRowCount)
        row.insertCell(0).innerHTML = index + 1
        row.insertCell(1).innerHTML = e.typeNumber + '-' + e.colorNo
        row.insertCell(2).innerHTML = e.colorName
        row.insertCell(3).innerHTML = e.commodityName
        row.insertCell(4).innerHTML = e.c05
        row.insertCell(5).innerHTML = e.c07
        row.insertCell(6).innerHTML = e.c09
        row.insertCell(7).innerHTML = e.c11
        row.insertCell(8).innerHTML = e.c13
        row.insertCell(9).innerHTML = e.c15
        row.insertCell(10).innerHTML = e.c17
        row.insertCell(11).innerHTML = e.c19
        row.insertCell(12).innerHTML = e.c21
        row.insertCell(13).innerHTML = e.c23
        row.insertCell(14).innerHTML = e.f
        row.insertCell(15).innerHTML = e.total
        row.insertCell(16).innerHTML = e.onePrice
        row.insertCell(17).innerHTML = e.money

        if (isA4) {
          // console.log(parseInt((index+1)/33))
          // console.log((index+1)%33 == 0)
          if (
            parseInt((index + 1) / 33) &&
            (index + 1) % 33 == 0 &&
            index + 1 != length
          ) {
            // console.log('33倍数')
            let pageIndex = index + 3 - parseInt(index / 33) * 33
            // console.log(pageIndex)
            // console.log(index+1)    // 33
            // console.log(length)     // 36
            let startingPoint = index - 32
            let pageTotal = 0
            let pageMoney = 0
            for (let j = startingPoint; j <= index; j++) {
              pageTotal += Number(this.styleNumberList[j].total)
              pageMoney += Number(this.styleNumberList[j].sellingPriceMoney)
            }

            let rowEnd = printTable.insertRow(printTable.FetchRowCount)
            rowEnd.insertCell(0).innerHTML = '本页小计：'
            printTable.rows[pageIndex].cells[0].colSpan = '2'
            rowEnd.insertCell(1).innerHTML = pageTotal
            printTable.rows[pageIndex].cells[1].colSpan = '2'
            rowEnd.insertCell(2).innerHTML = '汇总金额：'
            printTable.rows[pageIndex].cells[2].colSpan = '4'
            rowEnd.insertCell(3).innerHTML = pageMoney.toFixed(2)
            printTable.rows[pageIndex].cells[3].colSpan = '10'

            let newHead = document.createElement('div')
            newHead.classList.add('addPrintHead')
            newHead.innerHTML = `
              <p class="rightTag" style="top: ${
                ((index + 1) / 33) * 29.7 + 3
              }cm;">白联仓库 红联财务 黄联客户</p>
              <span class="printHead">
                ${this.companyName}${this.jxQuarter}客户退货单
              </span>
              <div class="info" style="height: 25px;">
                <p style="margin: 5px 0;">客户：${this.printVendorName}</p>
                <p style="margin: 5px 0;">联系人：${this.contact}</p>
                <p style="margin: 5px 0;">退货序号：${this.inputSequence}</p>
              </div>
              <div class="info" style="height: 25px;">
                <p style="margin: 5px 0;">客户电话：${this.phone}</p>
                <p style="margin: 5px 0;">出货类型：${this.shipType}</p>
                <p style="margin: 5px 0;">退货日期：${this.inputDate}</p>
              </div>
            `
            newHead.style.pageBreakBefore = 'always'
            this.insertAfter(newHead, printTable)

            let tableId = `printTable${(index + 1) / 33}`
            // console.log(tableId)
            let tableDom = document.createElement('table')
            tableDom.border = '1'
            tableDom.align = 'center'
            tableDom.id = tableId
            tableDom.innerHTML = `
              <thead>
                <tr>
                  <td style="width: 4%;padding: 0;" rowspan="2">序号</td>
                  <td style="width: 15%;padding: 0;" rowspan="2">型色</td>
                  <td style="width: 8%;padding: 0;" rowspan="2">颜色</td>
                  <td style="width: 15%;padding: 0;" rowspan="2">品名</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">05</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">07</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">09</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">11</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">13</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">15</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">17</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">19</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">21</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">23</td>
                  <td style="width: 3.8%;padding: 0;">F</td>
                  <td rowspan="2" style="width: 5%;">数量</td>
                  <td rowspan="2" style="width: 5%;">单价</td>
                  <td rowspan="2">金额</td>
                </tr>
                <tr>
                  <td style="border-top: 1px dotted;border-left: 1px dotted;">XS</td>
                  <td style="border-top: 1px dotted;">S</td>
                  <td style="border-top: 1px dotted;">M</td>
                  <td style="border-top: 1px dotted;">L</td>
                  <td style="border-top: 1px dotted;">XL</td>
                  <td style="border-top: 1px dotted;">2L</td>
                  <td style="border-top: 1px dotted;">3L</td>
                  <td style="border-top: 1px dotted;">4L</td>
                  <td style="border-top: 1px dotted;">5L</td>
                  <td style="border-top: 1px dotted;">6L</td>
                  <td style="border-top: 1px dotted;"></td>
                </tr>
              </thead>
            `
            // console.log(tableDom)
            // console.log(index)
            this.printStyleCount(e.typeNumber)
            this.insertAfter(tableDom, newHead)
            this.openPrint(true, index + 2, tableId)
            return
          }
          if (index + 1 == length) {
            let pageIndex = index + 3 - parseInt(index / 33) * 33
            // console.log('最后一行')
            let startingPoint = index < 33 ? 0 : parseInt(index / 33) * 33
            let pageTotal = 0
            let pageMoney = 0
            for (let j = startingPoint; j <= index; j++) {
              pageTotal += Number(this.styleNumberList[j].total)
              pageMoney += Number(this.styleNumberList[j].sellingPriceMoney)
            }
            let rowEnd = printTable.insertRow(printTable.FetchRowCount)
            rowEnd.insertCell(0).innerHTML = '本页小计：'
            printTable.rows[pageIndex].cells[0].colSpan = '2'
            rowEnd.insertCell(1).innerHTML = pageTotal
            printTable.rows[pageIndex].cells[1].colSpan = '2'
            rowEnd.insertCell(2).innerHTML = '汇总金额：'
            printTable.rows[pageIndex].cells[2].colSpan = '4'
            rowEnd.insertCell(3).innerHTML = pageMoney.toFixed(2)
            printTable.rows[pageIndex].cells[3].colSpan = '10'
          }
        } else {
          if (
            parseInt((index + 1) / 12) &&
            (index + 1) % 12 == 0 &&
            index + 1 != length
          ) {
            // console.log('12倍数')
            let pageIndex = index + 3 - parseInt(index / 12) * 12
            // console.log(pageIndex)
            // console.log(index+1)    // 12
            // console.log(length)     // 36
            let startingPoint = index - 11
            let pageTotal = 0
            let pageMoney = 0
            for (let j = startingPoint; j <= index; j++) {
              pageTotal += Number(this.styleNumberList[j].total)
              pageMoney += Number(this.styleNumberList[j].sellingPriceMoney)
            }

            let rowEnd = printTable.insertRow(printTable.FetchRowCount)
            rowEnd.insertCell(0).innerHTML = '本页小计：'
            printTable.rows[pageIndex].cells[0].colSpan = '2'
            rowEnd.insertCell(1).innerHTML = pageTotal
            printTable.rows[pageIndex].cells[1].colSpan = '2'
            rowEnd.insertCell(2).innerHTML = '汇总金额：'
            printTable.rows[pageIndex].cells[2].colSpan = '4'
            rowEnd.insertCell(3).innerHTML = pageMoney.toFixed(2)
            printTable.rows[pageIndex].cells[3].colSpan = '10'

            let newHead = document.createElement('div')
            newHead.classList.add('addPrintHead')
            newHead.innerHTML = `
              <p class="rightTag" style="top: ${
                ((index + 1) / 12) * 14.85 + 3
              }cm;">白联仓库 红联财务 黄联客户</p>
              <span class="printHead">
                ${this.companyName}${this.jxQuarter}客户退货单
              </span>
              <div class="info" style="height: 25px;">
                <p style="margin: 5px 0;">客户：${this.printVendorName}</p>
                <p style="margin: 5px 0;">联系人：${this.contact}</p>
                <p style="margin: 5px 0;">退货序号：${this.inputSequence}</p>
              </div>
              <div class="info" style="height: 25px;">
                <p style="margin: 5px 0;">客户电话：${this.phone}</p>
                <p style="margin: 5px 0;">出货类型：${this.shipType}</p>
                <p style="margin: 5px 0;">退货日期：${this.inputDate}</p>
              </div>
            `
            newHead.style.pageBreakBefore = 'always'
            this.insertAfter(newHead, printTable)

            let tableId = `printTable${(index + 1) / 12}`
            // console.log(tableId)
            let tableDom = document.createElement('table')
            tableDom.border = '1'
            tableDom.align = 'center'
            tableDom.id = tableId
            tableDom.innerHTML = `
              <thead>
                <tr>
                  <td style="width: 4%;padding: 0;" rowspan="2">序号</td>
                  <td style="width: 15%;padding: 0;" rowspan="2">型色</td>
                  <td style="width: 8%;padding: 0;" rowspan="2">颜色</td>
                  <td style="width: 15%;padding: 0;" rowspan="2">品名</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">05</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">07</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">09</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">11</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">13</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">15</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">17</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">19</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">21</td>
                  <td style="width: 3.8%;padding: 0;" nowrap="nowrap">23</td>
                  <td style="width: 3.8%;padding: 0;">F</td>
                  <td rowspan="2" style="width: 5%;">数量</td>
                  <td rowspan="2" style="width: 5%;">单价</td>
                  <td rowspan="2">金额</td>
                </tr>
                <tr>
                  <td style="border-top: 1px dotted;border-left: 1px dotted;">XS</td>
                  <td style="border-top: 1px dotted;">S</td>
                  <td style="border-top: 1px dotted;">M</td>
                  <td style="border-top: 1px dotted;">L</td>
                  <td style="border-top: 1px dotted;">XL</td>
                  <td style="border-top: 1px dotted;">2L</td>
                  <td style="border-top: 1px dotted;">3L</td>
                  <td style="border-top: 1px dotted;">4L</td>
                  <td style="border-top: 1px dotted;">5L</td>
                  <td style="border-top: 1px dotted;">6L</td>
                  <td style="border-top: 1px dotted;"></td>
                </tr>
              </thead>
            `
            // console.log(tableDom)
            // console.log(index)
            this.printStyleCount(e.typeNumber)
            this.insertAfter(tableDom, newHead)
            this.openPrint(false, index + 2, tableId)
            return
          }
          if (index + 1 == length) {
            let pageIndex = index + 3 - parseInt(index / 12) * 12
            // console.log('最后一行')
            let startingPoint = index < 12 ? 0 : parseInt(index / 12) * 12
            let pageTotal = 0
            let pageMoney = 0
            for (let j = startingPoint; j <= index; j++) {
              pageTotal += Number(this.styleNumberList[j].total)
              pageMoney += Number(this.styleNumberList[j].sellingPriceMoney)
            }
            let rowEnd = printTable.insertRow(printTable.FetchRowCount)
            rowEnd.insertCell(0).innerHTML = '本页小计：'
            printTable.rows[pageIndex].cells[0].colSpan = '2'
            rowEnd.insertCell(1).innerHTML = pageTotal
            printTable.rows[pageIndex].cells[1].colSpan = '2'
            rowEnd.insertCell(2).innerHTML = '汇总金额：'
            printTable.rows[pageIndex].cells[2].colSpan = '4'
            rowEnd.insertCell(3).innerHTML = pageMoney.toFixed(2)
            printTable.rows[pageIndex].cells[3].colSpan = '10'
          }
        }

        this.printStyleCount(e.typeNumber)
      }

      this.printStyle = this.styleList.length

      let int = setInterval(() => {
        if (this.printStyle) {
          clearInterval(int)
          let printArea = document.getElementById('p')
          let footBox = document.createElement('div')
          footBox.innerHTML = `
            <div class="info">
              <p style="margin: 5px 0;">款号合计：${this.printStyle}</p>
              <p style="margin: 5px 0;">售价合计：${this.printSellingPrice.toFixed(
                2
              )}</p>
              <p style="margin: 5px 0;">数量合计：${this.printTotal}</p>
              <p style="margin: 5px 0;">金额合计：${this.printMoney.toFixed(
                2
              )}</p>
            </div>
            <div class="info">
              <p style="margin: 5px 0;">操作员：${this.operator}</p>
              <p style="margin: 5px 0;">财务：</p>
              <p style="margin: 5px 0;">复核：</p>
              <p style="margin: 5px 28.7vw 5px 0;">备注：</p>
            </div>
          `
          printArea.appendChild(footBox)
          if (this.printType == '1') {
            let addressBox = document.createElement('div')
            addressBox.innerHTML = `
              <div id="printA">
                <div class="addressH1">
                  <p>收货地址：${this.address}</p>
                </div>
                <div class="addressH1">
                  <p>收货人：${this.printVendorName.split('_')[1]}</p>
                </div>
                <div class="addressH1">
                  <p>电话：${this.cellphone}</p>
                </div>
                <div class="addressH1">
                  <p>手机：${this.phone}</p>
                </div>
                <div class="addressH2">
                  <p>寄件人：${this.companyName}</p>
                  <p>联系电话：${this.companyPhone}</p>
                </div>
                <div class="addressH2">
                  <p>备注：${this.printRemark || ''}</p>
                </div>
                <div class="addressH2">
                  <p>单据类型：${this.shipType}</p>
                  <p>单据序号：${this.inputSequence}</p>
                  <p>${this.printStyle}</p>
                </div>
                <div class="addressH2">
                  <p>制单人：${this.operator}</p>
                  <p>${this.inputDate}</p>
                </div>
              </div>
            `
            addressBox.style.pageBreakBefore = 'always'
            printArea.appendChild(addressBox)
          }

          let printHtml = printArea.innerHTML
          let wind = window.open(
            '',
            'newwindow',
            'height=500, width=1000, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'
          )
          wind.document.body.innerHTML = printHtml
          let style = document.createElement('style')
          style.type = 'text/css'
          style.innerHTML = resources.printCSS
          wind.document.head.appendChild(style)
          this.$forceUpdate()
          QRCode.toCanvas(
            wind.document.getElementById('canvas'),
            '2' + this.inputSequence,
            {
              errorCorrectionLevel: 'low',
              width: 90,
              margin: 0,
              quality: 0.3,
              scale: 1
            },
            (error) => {
              if (error) throw error
              wind.print()
            }
          )

          return false
        }
      }, 500)
    },
    printStyleCount(s) {
      if (!this.styleList.length) {
        this.styleList.push(s)
      } else {
        let exist = 0
        for (const i of this.styleList) {
          // console.log(i)
          if (i == s) {
            exist = 1
            break
          }
        }
        if (!exist) {
          this.styleList.push(s)
        }
      }
    },
    // insertAfter(p,header1) // 因为js没有直接追加到指定元素后面的方法 所以要自己创建一个方法
    insertAfter(newElement, targetElement) {
      // newElement是要追加的元素 targetElement 是指定元素的位置
      let parent = targetElement.parentNode // 找到指定元素的父节点
      if (parent.lastChild == targetElement) {
        // 判断指定元素的是否是节点中的最后一个位置 如果是的话就直接使用appendChild方法
        parent.appendChild(newElement, targetElement)
      } else {
        parent.insertBefore(newElement, targetElement.nextSibling)
      }
    },

    showRevision() {
      switch (this.operationType) {
        case 1:
          this.showSupOrder = true
          break
        case 2:
          this.showCReviSion = true
          break
        case 3:
          this.$router.push({
            path: '/delete_document',
            query: { type: 4, sequence: this.inputSequence }
          })
          this.$store.commit('addNav', {
            label: '客户退货删单',
            name: 'delete_document'
          })
          break
        default:
          break
      }
      this.showpwd = false
    },
    determine(o) {
      // 确认补单
      this.showSupOrder = false
      this.$router.push({
        path: '/customer/client_return_mn',
        query: { oid: o, type: this.isRFID ? 1 : 0 }
      })
      this.$store.commit('minusNav', '客户退货')
      // this.$store.commit('addNav',{label:'客户退货',name:'client_return_mn',path:`/customer/client_return_mn?oid=${o}&type=${this.isRFID?1:0}`})
    },

    // 查询
    search(st = 0) {
      if (st) {
        this.currentPageLeft = 1
        this.$refs.paginationLeft.internalCurrentPage = 1
      }

      this.inputSequence = ''
      this.canvasUrl = ''
      this.sequenceDataList = []
      this.amount = 0
      this.sequenceData = []

      this.conditionList = []
      this.kindsNumberList = []
      this.dataLen = 0
      this.kindsNumberData = []

      let affirmInt
      // 查询条件是否是默认（0:是1：否， 默认只有开始时间和结束时间为查询条件）
      let defaultInquiry = 1
      let kindsNumberStr = ''

      switch (this.affirm) {
        case '全部':
          affirmInt = null
          break
        case '未收货':
          affirmInt = 1
          break
        case '未确认':
          affirmInt = 0
          break
        case '已完成':
          affirmInt = 2
      }

      if (
        !this.customerNo &&
        !this.inputSequence1 &&
        !this.receiptsNumber &&
        !this.warehouseNo &&
        !this.quarter &&
        !this.brandedName &&
        !this.commodityName &&
        !this.branchNumber &&
        !this.headOfficeNumber &&
        !this.beginningPeriod &&
        !this.remark
      ) {
        defaultInquiry = 0
      }
      let params = {
        twoInfo: this.twoDimensional ? 1 : 0,
        customerNo: this.customerNo,
        startTime: this.dateList ? this.dateList[0] + ' 00:00:00' : '',
        endTime: this.dateList ? this.dateList[1] + ' 23:59:59' : '',
        outSequence: this.inputSequence1,
        receiptsNumber: this.receiptsNumber,
        warehouseNo: this.warehouseNo,
        quarter: this.quarter,
        kindsNumber: this.kindsNumber,
        brandedName: this.brandedName,
        commodityName: this.commodityName,
        affirm: affirmInt,
        cooperateWay: this.cooperateWay == '全部' ? '' : this.cooperateWay,
        branchNumber: this.branchNumber,
        headOfficeNumber: this.headOfficeNumber,
        beginningPeriod: this.beginningPeriod ? 1 : 0,
        remark: this.remark,
        defaultInquiry,
        limit: this.limitLeft,
        page: this.currentPageLeft
      }
      // console.log(params)
      getOutInquire(params).then((res) => {
        this.adjustPrice = false
        this.currentPage = 1
        this.$refs.paginationRight.internalCurrentPage = 1

        if (res.data.code == 200) {
          this.sequenceDataList = res.data.data.outInquireTotalList || []
          this.sequenceDataList.sort((a, b) => {
            return b.outSequence.localeCompare(a.outSequence)
          })
          this.amount = res.data.total
          this.dataLenLeft = this.amount
          this.sequenceData = this.sequenceDataList

          this.sequenceDataList.forEach((e) => {
            e.customerStr = e.no + '.' + e.name
          })

          this.conditionList = res.data.data.outInquireInfoList || []
          this.kindsNumberList = res.data.data.outInquireInfoList || []
          this.styleNumberList = res.data.data.totalTwoList || []
          this.detailTwo = res.data.data.customerOutInfoTwos || []

          this.kindsNumberList.forEach((e) => {
            e.time = e.purchaseTime.slice(0, 10)
            e.colorSize = e.colorName + ' ' + e.size
          })
          this.summation.sum = res.data.data.sumNumberAndMoney.number
          this.summation.money = res.data.data.sumNumberAndMoney.money

          if (this.twoDimensional) {
            // 计算总数
            this.summation.c05 = 0
            this.summation.c07 = 0
            this.summation.c09 = 0
            this.summation.c11 = 0
            this.summation.c13 = 0
            this.summation.c15 = 0
            this.summation.c17 = 0
            this.summation.c19 = 0
            this.summation.c21 = 0
            this.summation.c23 = 0
            this.summation.f = 0

            this.styleNumberList.forEach((e) => {
              e.total =
                Number(e.c05) +
                Number(e.c07) +
                Number(e.c09) +
                Number(e.c11) +
                Number(e.c13) +
                Number(e.c15) +
                Number(e.c17) +
                Number(e.c19) +
                Number(e.c21) +
                Number(e.c23) +
                Number(e.f)
              e.sellingPriceMoney = (e.sellingPrice * e.total).toFixed(2)

              this.summation.c05 += Number(e.c05)
              this.summation.c07 += Number(e.c07)
              this.summation.c09 += Number(e.c09)
              this.summation.c11 += Number(e.c11)
              this.summation.c13 += Number(e.c13)
              this.summation.c15 += Number(e.c15)
              this.summation.c17 += Number(e.c17)
              this.summation.c19 += Number(e.c19)
              this.summation.c21 += Number(e.c21)
              this.summation.c23 += Number(e.c23)
              this.summation.f += Number(e.f)

              // this.summation.sum += Number(e.total)
              // this.summation.money += Number(e.money)

              if (e.c05 === 0) e.c05 = ''
              if (e.c07 === 0) e.c07 = ''
              if (e.c09 === 0) e.c09 = ''
              if (e.c11 === 0) e.c11 = ''
              if (e.c13 === 0) e.c13 = ''
              if (e.c15 === 0) e.c15 = ''
              if (e.c17 === 0) e.c17 = ''
              if (e.c19 === 0) e.c19 = ''
              if (e.c21 === 0) e.c21 = ''
              if (e.c23 === 0) e.c23 = ''
              if (e.f === 0) e.f = ''
            })
            this.dataLen = this.styleNumberList.length
            this.kindsNumberData = this.styleNumberList.slice(0, this.limit)
          } else {
            this.dataLen = this.conditionList.length
            this.kindsNumberData = this.conditionList.slice(0, this.limit)
          }

          this.$nextTick(() => {
            this.$refs.table2.doLayout()
          })
        } else {
          this.$message('暂无数据')
        }
      })
    },

    // 确认
    confirm() {
      if (!this.pick) {
        this.$message.info('店铺数据仅支持收货操作')
        return
      }
      if (!this.inputSequence) {
        this.$alert('请先选择一条数据再进行确定操作', '', {
          confirmButtonText: '确定'
        })
        return
      }
      this.sequenceRow.customerNo = this.sequenceRow.no
      this.sequenceRow.sequence = this.sequenceRow.inputSequence
      let d = {
        customerDTO: this.sequenceRow,
        validList: this.selectList
      }
      affirmOut(JSON.stringify(d)).then((res) => {
        if (res.data.code == 200) {
          this.sequenceRow.affirm = 1
          this.$message({
            message: '确认成功',
            type: 'success'
          })
          this.isConfirm = true
        } else {
          this.$message.error('确认失败')
        }
      })
    },

    pickUp() {
      if (!this.inputSequence) {
        this.$alert('请先选择一条数据再进行收货操作', '', {
          confirmButtonText: '确定'
        })
        return
      }
      receipt(this.selectList).then((res) => {
        if (res.data.code == 200) {
          for (const i of this.sequenceData) {
            if (i.inputSequence == this.inputSequence) {
              i.mnemonicCode = 1
              break
            }
          }
          this.$message({
            message: '收货成功',
            type: 'success'
          })
          this.sequenceRow.mnemonicCode = 1
          this.pick = true
        } else {
          this.$message.error('收货失败')
        }
      })
    },

    // 审核
    audit() {
      if (!this.inputSequence) {
        this.$alert('请先选择一条数据再进行确定操作', '', {
          confirmButtonText: '确定'
        })
        return
      }
      checkYse(JSON.stringify([this.inputSequence])).then((res) => {
        if (res.data.code == 200) {
          for (const i of this.sequenceData) {
            if (i.inputSequence == this.inputSequence) {
              i.checks = 1
              break
            }
          }
          this.$message({
            message: '审核成功',
            type: 'success'
          })
          this.isAudit = true
        } else {
          this.$message.error('审核失败')
        }
      })
    },

    // 反审
    umpire() {
      if (!this.inputSequence) {
        this.$alert('请先选择一条数据再进行确定操作', '', {
          confirmButtonText: '确定'
        })
        return
      }
      checkNo(JSON.stringify([this.inputSequence])).then((res) => {
        if (res.data.code == 200) {
          for (const i of this.sequenceData) {
            if (i.inputSequence == this.inputSequence) {
              i.checks = 0
              break
            }
          }
          this.$message({
            message: '反审成功',
            type: 'success'
          })
          this.isAudit = false
        } else {
          this.$message.error('反审失败')
        }
      })
    },

    // 客户整进
    customerInput() {
      if (!this.inputSequence) {
        this.$alert('请先选择一条数据再进行确定操作', '', {
          confirmButtonText: '确定'
        })
        return
      }
      if (!this.inputCustomerNo) {
        this.$alert('请填写进货客户编号', '必填项为空', {
          confirmButtonText: '确定'
        })
        return
      }
      let isExist = 0
      for (const i of this.customerList) {
        if (i.value == this.inputCustomerNo) {
          isExist = 1
          break
        }
      }
      if (!isExist) {
        this.$alert('进货客户编号不存在', '', {
          confirmButtonText: '确定'
        })
        return
      }
      this.sequenceRow.customerInputNo = this.inputCustomerNo
      this.sequenceRow.totalShowVOList = this.kindsNumberData
      allOut(JSON.stringify(this.sequenceRow)).then((res) => {
        if (res.data.code == 200) {
          this.$message({
            message: '客户整进成功',
            type: 'success'
          })
          this.isOut1 = true
        } else {
          this.$message.error('客户整进失败')
        }
      })
    },

    // 厂商整退
    ManufacturerReturn() {
      let kindsNumberMap = {}
      if (this.inputSequence) {
        // 整退一条
        if (!this.sequenceRow.affirm) {
          // 还没确认
          this.$alert('当前选中数据未确认，请确认后再进行厂商整退操作', '', {
            confirmButtonText: '确定'
          })
          return
        }
        // if (!this.outManufacturerNo) {
        //   this.$alert('请填写厂退厂商编号', '', {
        //     confirmButtonText: '确定'
        //   })
        //   return
        // }

        this.kindsNumberData.forEach((e) => {
          kindsNumberMap[e.kindsNumber] = e.sum
        })
        // 数据来源（0：rfid 1：货号）
        // this.sequenceRow.dataSource = this.sequenceRow.isNewBuild
        // this.sequenceRow.brandedName = this.sequenceRow.isNewBuild
        // this.sequenceRow.sequence = this.sequenceRow.outSequence
        // this.sequenceRow.kindsNumberMap = kindsNumberMap
        let param = {
          outSequence: this.sequenceRow.outSequence,
          warehouseNo: this.sequenceRow.warehouseNo
        }
        // console.log(param)
        // return
        retreat(param).then((res) => {
          if (res.data.code == 200) {
            this.$message({
              message: '厂商整退成功',
              type: 'success'
            })
            this.isOut2 = true
            this.outManufacturerSequence = res.data.data.resultSet[0]
          } else {
            this.$message.error('厂商整退失败')
          }
        })
      } else {
        // 全部整退
        for (const e of this.sequenceData) {
          if (!e.affirm) continue
          this.kindsNumberList.forEach((f) => {
            if (e.outSequence == f.sequence) {
              kindsNumberMap[f.kindsNumber] = f.sum
            }
          })
          e.dataSource = this.sequenceRow.isNewBuild
          e.sequence = this.sequenceRow.outSequence
          e.kindsNumberMap = kindsNumberMap
          retreat(JSON.stringify(this.sequenceRow)).then((res) => {
            if (res.data.code == 200) {
              this.$message({
                message: '厂商整退成功',
                type: 'success'
              })
              this.outManufacturerSequence = res.data.data
            } else {
              this.$message.error('厂商整退失败')
            }
          })
        }
      }
    },

    dele() {
      // if (!this.pick) {
      //   this.$message.info("店铺数据仅支持收货操作")
      //   return
      // }
      if (!this.inputSequence) {
        this.$message.info('请先选择一条数据再进行删除操作')
        return
      }
      this.operationType = 3
      this.showpwd = true
    },

    // 客户编号失去焦点
    customerNoBlur() {
      if (this.customerNo) {
        for (const i of this.customerList) {
          if (this.customerNo == i.value) {
            this.customerName = i.label
            this.discount = i.discount
            return
          }
        }
        this.$alert('无此客户编号', '', {
          confirmButtonText: '确定'
        })
        this.customerNo = ''
        this.customerName = ''
      } else {
        this.customerName = ''
      }
    },
    // 仓库编号失去焦点
    warehouseNoBlur() {
      if (this.warehouseNo) {
        for (const i of this.warehouseList) {
          if (this.warehouseNo == i.value) {
            this.warehouseName = i.label
            return
          }
        }
        this.$alert('无此仓库编号', '', {
          confirmButtonText: '确定'
        })
        this.warehouseNo = ''
        this.warehouseName = ''
      } else {
        this.warehouseName = ''
      }
    },

    rowClick(row) {
      // console.log(row.affirm,row.isNewBuild)
      this.dataLen = this.kindsNumberList.length
      this.canvasUrl = row.printImage

      this.currentPage = 1

      this.$refs.table2.setCurrentRow({})
      this.detailRow = {}
      this.sequenceRow = row

      this.inputSequence = row.outSequence
      this.printVendor = row.no
      this.printVendorName = row.no + '_' + row.name
      this.inputDate = row.outTime.slice(0, 10)
      this.shipType = row.cooperateWay
      this.printRemark = row.remark

      // this.customerNo = row.no
      // this.warehouseNo = row.warehouseNo

      // this.customerNoBlur()
      // this.warehouseNoBlur()

      // 客户整进过没
      if (row.totalInputSequence) {
        this.isOut1 = true
      } else {
        this.isOut1 = false
      }

      // 确认了没
      if (row.affirm) {
        this.isConfirm = true
        if (Number(row.isNewBuild)) {
          this.Dis = false
          this.Dis1 = false
        } else {
          this.Dis = true
          this.Dis1 = true
        }
      } else {
        this.isConfirm = false
        if (Number(row.isNewBuild)) {
          this.Dis = false
          this.Dis1 = false
        } else {
          this.Dis = false
          this.Dis1 = true
        }
      }

      // 审核了没
      if (row.checks) {
        this.isAudit = true
      } else {
        this.isAudit = false
      }

      // 是不是读卡进的
      if (row.isNewBuild) {
        this.isRFID = false
      } else {
        this.isRFID = true
      }

      // 能不能收货
      if (row.mnemonicCode) {
        this.pick = true
      } else {
        this.pick = false
      }

      this.selectList = []
      this.summation.sum = row.number
      this.summation.sellingPriceMoney = 0
      this.summation.money = row.money

      if (this.twoDimensional) {
        this.styleNumberList = []
        // 计算总数
        this.summation.c05 = 0
        this.summation.c07 = 0
        this.summation.c09 = 0
        this.summation.c11 = 0
        this.summation.c13 = 0
        this.summation.c15 = 0
        this.summation.c17 = 0
        this.summation.c19 = 0
        this.summation.c21 = 0
        this.summation.c23 = 0
        this.summation.f = 0
        this.detailTwo.forEach((e) => {
          if (this.inputSequence == e.outSequence) {
            e.total =
              Number(e.c05) +
              Number(e.c07) +
              Number(e.c09) +
              Number(e.c11) +
              Number(e.c13) +
              Number(e.c15) +
              Number(e.c17) +
              Number(e.c19) +
              Number(e.c21) +
              Number(e.c23) +
              Number(e.f)
            e.sellingPriceMoney = (e.sellingPrice * e.total).toFixed(2)
            this.summation.c05 += Number(e.c05)
            this.summation.c07 += Number(e.c07)
            this.summation.c09 += Number(e.c09)
            this.summation.c11 += Number(e.c11)
            this.summation.c13 += Number(e.c13)
            this.summation.c15 += Number(e.c15)
            this.summation.c17 += Number(e.c17)
            this.summation.c19 += Number(e.c19)
            this.summation.c21 += Number(e.c21)
            this.summation.c23 += Number(e.c23)
            this.summation.f += Number(e.f)
            this.summation.sellingPriceMoney += Number(e.sellingPriceMoney)

            if (e.c05 === 0) e.c05 = ''
            if (e.c07 === 0) e.c07 = ''
            if (e.c09 === 0) e.c09 = ''
            if (e.c11 === 0) e.c11 = ''
            if (e.c13 === 0) e.c13 = ''
            if (e.c15 === 0) e.c15 = ''
            if (e.c17 === 0) e.c17 = ''
            if (e.c19 === 0) e.c19 = ''
            if (e.c21 === 0) e.c21 = ''
            if (e.c23 === 0) e.c23 = ''
            if (e.f === 0) e.f = ''

            this.styleNumberList.push(e)
          }
        })
        this.dataLen = this.styleNumberList.length
        this.kindsNumberData = this.styleNumberList.slice(0, this.limit)
      } else {
        this.kindsNumberList.forEach((e) => {
          if (this.inputSequence == e.sequence) {
            this.selectList.push(e)
            if (this.selectList.length == 1) {
              // 厂商整退过没
              if (e.factoryTotalOutSequence) {
                this.isOut12 = true
              } else {
                this.isOut2 = false
              }
            }
          }
        })
        this.dataLen = this.selectList.length
        this.kindsNumberData = this.selectList.slice(0, this.limit)
      }
      this.$nextTick(() => {
        this.$refs.table2.doLayout()
      })
      console.log(row.mnemonicCode)
      if (row.mnemonicCode == 0) {
        this.Dis = false
      }
    },
    detailClick(row) {
      return
      if (this.twoDimensional) return
      this.$refs.table1.setCurrentRow({})
      this.detailRow = row

      this.inputSequence = row.sequence

      // 确认了没
      if (row.affirm) {
        this.isConfirm = true
      } else {
        this.isConfirm = false
      }

      // 客户整进过没
      if (row.totalInputSequence) {
        this.isOut1 = true
      } else {
        this.isOut1 = false
      }

      // 厂商整退过没
      if (row.factoryTotalOutSequence) {
        this.isOut12 = true
      } else {
        this.isOut2 = false
      }

      // 审核了没
      // console.log(row.checks)
      // if (row.checks) {
      //   this.isAudit = true
      // } else {
      //   this.isAudit = false
      // }

      // 是不是读卡进的
      if (row.isNewBuild) {
        this.isRFID = false
      } else {
        this.isRFID = true
      }

      // 能不能收货
      if (row.mnemonicCode) {
        this.pick = true
      } else {
        this.pick = false
      }
    },

    // 每页显示页数改变
    handleSizeChange(val) {
      this.limit = val
      if (this.adjustPrice) {
        this.dataLen = this.adjustPriceList.length
        this.kindsNumberData = this.adjustPriceList.slice(
          0,
          this.currentPage * this.limit
        )
        return
      }
      switch (this.twoDimensional) {
        case true:
          this.dataLen = this.styleNumberList.length
          this.kindsNumberData = this.styleNumberList.slice(
            0,
            this.currentPage * this.limit
          )
          break
        case false:
          if (this.inputSequence) {
            this.dataLen = this.selectList.length
            this.kindsNumberData = this.selectList.slice(
              0,
              this.currentPage * this.limit
            )
          } else {
            this.dataLen = this.kindsNumberList.length
            this.kindsNumberData = this.conditionList.slice(
              0,
              this.currentPage * this.limit
            )
          }
          break
      }
    },
    // 当前页改变
    handleCurrentChange(val) {
      this.currentPage = val
      if (this.adjustPrice) {
        this.kindsNumberData = this.adjustPriceList.slice(
          (this.currentPage - 1) * this.limit,
          this.currentPage * this.limit
        )
        return
      }
      switch (this.twoDimensional) {
        case true:
          this.kindsNumberData = this.styleNumberList.slice(
            (this.currentPage - 1) * this.limit,
            this.currentPage * this.limit
          )
          break
        case false:
          if (this.inputSequence) {
            this.kindsNumberData = this.selectList.slice(
              (this.currentPage - 1) * this.limit,
              this.currentPage * this.limit
            )
          } else {
            this.kindsNumberData = this.conditionList.slice(
              (this.currentPage - 1) * this.limit,
              this.currentPage * this.limit
            )
          }
          break
      }
    },

    handleSizeChangeLeft(val) {
      this.limitLeft = val
      this.search(1)
      // this.sequenceData = this.sequenceDataList.slice((this.currentPageLeft-1)*this.limitLeft,this.currentPageLeft*this.limitLeft)
    },
    handleCurrentChangeLeft(val) {
      this.currentPageLeft = val
      this.search()
      // this.sequenceData = this.sequenceDataList.slice((this.currentPageLeft-1)*this.limitLeft,this.currentPageLeft*this.limitLeft)
    },

    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        const prop = column.property
        switch (prop) {
          case 'sum':
            sums[index] = this.summation.sum || ''
            break
          case 'total':
            sums[index] = this.summation.sum || ''
            break
          case 'sellingPriceMoney':
            sums[index] =
              this.summation.sellingPriceMoney || this.summation.money || ''
            break
          case 'money':
            sums[index] = this.summation.money || ''
            break
          case 'c05':
            sums[index] = this.summation.c05 || ''
            break
          case 'c07':
            sums[index] = this.summation.c07 || ''
            break
          case 'c09':
            sums[index] = this.summation.c09 || ''
            break
          case 'c11':
            sums[index] = this.summation.c11 || ''
            break
          case 'c13':
            sums[index] = this.summation.c13 || ''
            break
          case 'c15':
            sums[index] = this.summation.c15 || ''
            break
          case 'c17':
            sums[index] = this.summation.c17 || ''
            break
          case 'c19':
            sums[index] = this.summation.c19 || ''
            break
          case 'c21':
            sums[index] = this.summation.c21 || ''
            break
          case 'c23':
            sums[index] = this.summation.c23 || ''
            break
          case 'f':
            sums[index] = this.summation.f || ''
            break
        }
        let decimal = sums[index] ? sums[index].toString().split('.')[1] : ''
        if (decimal && decimal.length > 2) {
          sums[index] = sums[index].toFixed(2)
        }
      })
      return sums
    },

    dividerClick() {
      let content1 = document.getElementById('content1')
      let content2 = document.getElementById('content2')
      if (this.areaFlag) {
        content1.style.width = '30%'
        content2.style.width = '69%'
      } else {
        content1.style.width = '60%'
        content2.style.width = '39%'
      }
      this.areaFlag = !this.areaFlag
    },

    changeCellStyle({ row, column, rowIndex, columnIndex }) {
      let style = 'height:26px;padding:0;'
      if (!row.affirm) {
        // return style + `background-color:${this.$store.state.unconfirmedBG};`
      } else if (!row.mnemonicCode) {
        // return style + `background-color:${this.$store.state.notReceiveBG};`
      } else if (row.transferCargoInfo) {
        // return style + `background-color:${this.$store.state.transferCargoInfoBG};`
      } else {
        // return style
      }
      return style
    }
  },
  created() {
    this.inpList = this.getInput()
    // 默认选之前一周
    // this.dateList = [this.searchDate(7),this.searchDate()]

    this.knhList = this.knhList1

    if (localStorage.getItem('jx_Ttitle1')) {
      this.selectHeaderList = localStorage.getItem('jx_Ttitle1').split(',')
    }

    // 获取所有客户信息
    this.customerList = []
    getClient({ limit: 99999 }).then((res) => {
      if (res.data.code == 200) {
        let list = res.data.data
        list.forEach((e) => {
          if (e.stop != 1) {
            this.customerList.push({
              value: e.no,
              label: e.name,
              discount: e.sellDiscount
            })
          }
        })
        if (this.jxAgent) {
          for (const i of this.customerList) {
            if (i.label == this.operator) {
              this.customerNo = i.value
              this.customerName = i.value
              break
            }
          }
        }
      }
    })
    // 获取仓库信息
    getWarehouse({ limit: 99999 }).then((res) => {
      if (res.data.code == 200) {
        let list = res.data.data
        list.sort((a, b) => {
          return a.no.localeCompare(b.no)
        })
        list.forEach((e) => {
          this.warehouseList.push({
            value: e.no,
            label: e.name,
            company: e.brandedCompany
          })
          if (e.isMainWarehouse) {
            this.warehouseNo = e.no
            this.warehouseName = e.name
          }
        })
      }
      // console.log(this.warehouseList)
    })
    // 获取品名信息
    getProductName({ limit: 99999 }).then((res) => {
      if (res.data.code == 200) {
        let list = res.data.data
        list.forEach((e) => {
          this.commodityNameList.push({ value: e.name, label: e.name })
        })
      }
    })
    // 获取品牌
    getBranded({ limit: 99999 }).then((res) => {
      res.data.data.forEach((e) => {
        this.brandList.push({ value: e.name, label: e.name })
      })
    })

    // 获取季度
    getQuarter({ limit: 99999 }).then((res) => {
      if (res.data.code == 200) {
        res.data.data.forEach((e) => {
          this.quarterList.push({ value: e.name, label: e.name })
        })
      }
    })

    getSystemConfig({ limit: 99999 }).then((res) => {
      if (res.data.data) {
        this.companyName = res.data.data.companyName
        this.companyPhone = res.data.data.phone
      }
    })
  }
}
</script>
<style scoped>
.clientReturnQuery {
  margin-right: 0.5vw;
  padding: 0 15px;
  background-color: white;
  height: 95vh;
  position: relative;
  overflow: hidden;
}
.crq_top {
  padding-bottom: 1vh;
  white-space: nowrap;
  left: -2vw;
  position: relative;
}
.crq_top p {
  display: inline-block;
  line-height: 30px;
  width: 70px;
  text-align: right;
  margin-right: 10px;
}
.crq_inp {
  width: 3vw;
  margin-right: 0.5vw;
}
.crq_select {
  width: 4.5vw;
}
.crq_inp1 {
  width: 8vw;
}
.crq_top1 {
  padding-bottom: 1vh;
  white-space: nowrap;
}
.crq_top1 p {
  display: inline-block;
  margin-right: 10px;
}
.crq_top1 div {
  display: inline-block;
}
.crq_top1 div:last-child {
  margin-right: 485px;
}
.crq_button {
  padding: 1vh 0;
  justify-content: space-between;
  white-space: nowrap;
}
.crq_button > div {
  display: inline-block;
}
.crq_tab {
  display: flex;
  width: 100%;
  height: 70%;
}
#content1 {
  width: 30%;
}
#content2 {
  width: 69%;
}
.divider {
  width: 1%;
  height: 99%;
  background-color: #f4f4f4;
  cursor: pointer;
}
.divider i {
  position: absolute;
  top: 50%;
  font-weight: 1000;
  color: #017aff;
}
.footView span {
  float: left;
  margin-right: 48px;
  line-height: 6vh;
  font-size: 14px;
}
.footView span i {
  margin-right: 5px;
}
.clientReturnQuery .exPort {
  width: 260px;
  height: 140px;
  background: white;
  position: absolute;
  top: 26%;
  left: 32%;
  z-index: 2;
  padding: 10px 15px;
  box-shadow: 3px 3px 3px #f4f4f4;
}
.clientReturnQuery .exPort div:first-child {
  font-weight: 700;
  margin-bottom: 5px;
}
.clientReturnQuery .exPort div:last-child {
  float: right;
  margin: 10px 0 0 0;
}
.clientReturnQuery .print {
  width: 260px;
  height: 120px;
  background: white;
  position: absolute;
  top: 26%;
  left: 37%;
  z-index: 2;
  padding: 10px 15px;
  box-shadow: 3px 3px 3px #f4f4f4;
}
.clientReturnQuery .print div:first-child {
  font-weight: 700;
  margin-bottom: 5px;
}
.clientReturnQuery .print div:last-child {
  float: right;
  margin: 10px 0 0 0;
}
#createImg {
  margin-top: 200px;
}
.tip {
  border: 1px;
  border-radius: 50%;
  width: 13px;
  height: 13px;
  margin: 6px 5px 0 5px;
}
.tip1 {
  border: 1px;
  border-radius: 50%;
  width: 13px;
  height: 13px;
  margin: 6px 1px 0 4px;
}
</style>

<style>
.clientReturnQuery .el-input__icon {
  line-height: 23px;
}
.clientReturnQuery .crq_top .el-input__inner,
.clientReturnQuery .crq_top1 .el-input__inner {
  height: 30px !important;
  padding: 0 5px;
}
.clientReturnQuery .crq_button .el-checkbox.is-bordered {
  padding: 4px 5px 0 5px;
  height: 30px;
}
.clientReturnQuery .print .el-radio {
  margin-right: 19px;
}
.clientReturnQuery .el-cascader__tags .el-tag {
  max-width: 55%;
}
.clientReturnQuery .crq_top .el-date-editor {
  width: 20.1vw;
}
.clientReturnQuery .el-range-separator {
  line-height: 23px;
  width: 10%;
}
.clientReturnQuery .el-pagination .el-select .el-input .el-input__inner,
.clientReturnQuery .el-pagination .el-select .el-input {
  width: 90px;
}
.clientReturnQuery .el-pagination {
  float: right;
  margin-top: 5px;
}
.clientReturnQuery .el-input--mini .el-input__inner {
  height: 23px;
}
.clientReturnQuery .el-table__footer td {
  height: 26px;
}
.clientReturnQuery .el-table .cell {
  padding: 0 0 0 5px;
}

.clientReturnQuery
  .el-pagination--small
  .el-pagination__editor.el-input
  .el-input__inner {
  width: 40px;
}
</style>
